package com.eshop.order.service;

import com.eshop.base.dao.OrderMapper;
import com.eshop.base.model.Order;
import com.eshop.base.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * <p>
 * 订单主表 服务实现类
 * </p>
 *
 * @author Your Name
 * @since 2025-05-11
 */
@Slf4j
@Service
@DubboService
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public Order create(String orderNo) {
        Order order = new Order();
        order.setUserId(1L);
        order.setOrderNo(orderNo);
        order.setTotalAmount(BigDecimal.valueOf(100010));
        order.setPayAmount(BigDecimal.valueOf(1000));
        order.setFreightAmount(BigDecimal.valueOf(100));
        order.setStatus((byte) 1);
        order.setRemark("购物车订单:" + orderNo);
        orderMapper.insert(order);
        log.info(order.toString());
        return order;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Order transCreate(String orderNo) {
        return create(orderNo);
    }
}
